﻿String.prototype.trim = String.prototype.trim || function ()
{
    return this.replace(/^\s+|\s+$/g, "");
};
String.prototype.replaceComplete = String.prototype.replaceComplete || function (replacee, replacer)
{
	var index = 0;
	var str = this.toString();
	while (str.indexOf(replacee) >= 0)
	{
		if (++index > 100)
			throw 'infinite looping replacing "' + replacee + '" with "' + replacer + '" in "' + str + '"';
		str = str.replace(replacee, replacer);
	}
	return str;
};
String.prototype.toSentenceCase = String.prototype.toSentenceCase || function ()
{
    try
    {
        result = '';
        var sentenceStart = true;
        for (var index = 0; index < this.length; index++)
        {
            var ch = this[index];
            if (sentenceStart == true && (ch != ' ') && (ch != '\t') && (ch != '\n'))
            {
                result = result + ch.toUpperCase();
                sentenceStart = false;
            }
            else
            {
                result = result + ch.toLowerCase();
                if (ch == '.' || ch == ' ')
                    sentenceStart = true;
            }
            //alert('result so far: ' + result);
        }
        return result;
    }
    catch (e)
    {
        alert('String.toSentenceCase() error: ' + e);
        return this;
    }
}

